package com.trg.flex.search
{
	[RemoteClass(alias="com.trg.search.Field")]
	public class Field
	{
		public function Field(property:String=null, key:String=null) {
			this.property = property;
			this.key = key;
		}
		
		public static const OP_PROPERTY : int = 0;
		public static const OP_COUNT : int = 1;
		public static const OP_COUNT_DISTINCT : int = 2;
		public static const OP_MAX : int = 3;
		public static const OP_MIN : int = 4;
		public static const OP_SUM : int = 5;
		public static const OP_AVG : int = 6;
		
		public var property:String;
		public var key:String;
		public var operator:int = 0;
		
		[Inspectable(enumeration="PROPERTY,COUNT,COUNT DISTINCT,MAX,MIN,SUM,AVG", defaultValue="PROPERTY")]
		public function set op(value:String):void {
			if (value == "PROPERTY") {
				operator = OP_PROPERTY;
			} else if (value == "COUNT") {
				operator = OP_COUNT;
			} else if (value == "COUNT DISTINCT") {
				operator = OP_COUNT_DISTINCT;
			} else if (value == "MAX") {
				operator = OP_MAX;
			} else if (value == "MIN") {
				operator = OP_MIN;
			} else if (value == "SUM") {
				operator = OP_SUM;
			} else if (value == "AVG") {
				operator = OP_AVG;
			} else {
				throw new Error("Invalid Filter operator '" + value + "'");
			}
		}
	}
}